# -*- coding: utf-8 -*-
require 'gtk2'
require './Modele/Dbconect'
require './Modele/Parking'

class NewParking < Gtk::Builder

  def initialize(xml)
    super()
    self << xml
    self['window2'].signal_connect("destroy") { onDestroy }
    self['window2'].show_all
      
    self.connect_signals{ |handler| method(handler) }
  end
  
  def on_validate
    if File.exist?("#{self['namepark'].text}.db") || self['namepark'].text==""  then
      dialog = Gtk::Dialog.new("Information", self, Gtk::Dialog::DESTROY_WITH_PARENT,[ Gtk::Stock::OK, Gtk::Dialog::RESPONSE_NONE ])
      dialog.signal_connect('response') { dialog.destroy }
      if !(self['namepark'].text=="") then
        dialog.vbox.add(Gtk::Label.new(" Vous avez déjà créé ce parking, veuillez choisir un nouveau nom ! "))
      else
        dialog.vbox.add(Gtk::Label.new(" Le nom du parking ne peut pas être vide ! "))
      end  
      dialog.show_all
    else
      Dbconect.creationbd(self['namepark'].text)
      Parking.new(self['namepark'].text,Integer(self['nbplace'].text),Integer(self['entry1'].text))
      puts "Parking #{self['namepark'].text} créé"
      LoadParking.new("View/parking.glade",self['namepark'].text)
      self['window2'].destroy
    end
    
  end
  
  def on_cancel
    self['window2'].destroy
  end
  
  def delete
      
  end
  
  def onDestroy
    self['window2'].destroy
  end

end